
package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.NoneTalkListBean;
import hz.mobileproject.pda.listener.Send_end_Callroll_inter;


/**
 * Created by YOLANDA on 2016/7/22.
 */
public class NoneTalkListAdapter extends  RecyclerView.Adapter<NoneTalkListAdapter.ViewHolder> {


    private final Context context;
    public List<NoneTalkListBean> datas = null;
    private Send_end_Callroll_inter callroll_inter;
    private Boolean onOff;


    public NoneTalkListAdapter(Context context, List<NoneTalkListBean> noneTalkListBeans) {
        this.context = context;
        this.datas = noneTalkListBeans;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_person,viewGroup,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }
    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
//        viewHolder.mTextView.setText(datas[position]);
        viewHolder.mPRID.setText(String.valueOf(datas.get(position).prison_rank));
        viewHolder.tv_NAME.setText(String.valueOf(datas.get(position).prisoner_name));
        viewHolder.tv_no.setText(String.valueOf(datas.get(position).department_name));
        viewHolder.PR_LEVEL.setText(String.valueOf(datas.get(position).time_check));

    }
    //获取数据的数量
    @Override
    public int getItemCount() {

        return datas==null?0:datas.size();
    }

    public void setData(List<NoneTalkListBean> noneTalkListBeans) {
        datas.clear();
        if(noneTalkListBeans == null) {
            noneTalkListBeans = new ArrayList<>();
        }
        datas.addAll(noneTalkListBeans);
        notifyDataSetChanged();
    }


    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mPRID;
        public TextView tv_NAME;
        public TextView tv_no;   //时间, 现在改成监区
        public TextView PR_LEVEL;

        public ViewHolder(View view) {
            super(view);
            mPRID = (TextView) view.findViewById(R.id.PR_id);
            tv_NAME = (TextView) view.findViewById(R.id.tv_NAME);
            tv_no = (TextView) view.findViewById(R.id.tv_no);
            PR_LEVEL = (TextView) view.findViewById(R.id.PR_LEVEL);
        }
    }


    public void addData(List<NoneTalkListBean> datass) {
        if(datass==null){
            return;
        }
        datas.addAll(datass);
        notifyDataSetChanged();
    }

    public void clearAddAll(List<NoneTalkListBean> datass) {
        datas.clear();
        if(datass==null){
            return;
        }
        datas = datass;
        notifyDataSetChanged();
    }


    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

}
